<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends CommonController {
    public function index(){


        if(!S('hotques')){
            echo '888';
            $hotques = D('question')->getHotTen();

            S('hotques',$hotques,90);
        }else{

            echo "9999";

            $hotques = S('hotques');

        }

        $hotuser = D('user') ->getHotTen();

        $cate = M('cate')->select();


        $notice = M('question')->where(['cid'=>5])->select();


        $topques = M('question t1')->field("t1.*,t2.nickname,t2.face,t3.cname")->join("user t2 on t1.uid=t2.uid")->join("cate t3 on t1.cid=t3.cid")->where(['t1.good'=>'2'])->select();


        $count = M('question')->count();

        $Page  = new \Think\Page($count,5);

        $show  = $Page->show();// 分页显示输出


        $allques = M('question t1')->field("t1.*,t2.nickname,t2.face,t3.cname")->join("user t2 on t1.uid=t2.uid")->join("cate t3 on t1.cid=t3.cid")->order('ctime desc')->limit($Page->firstRow.','.$Page->listRows)->select();


        $this->assign('cate',$cate);

        $this->assign('topques',$topques);

        $this->assign('hotques',$hotques);

        $this->assign('allques',$allques);

        $this->assign('show',$show);
        $this->assign('notice',$notice);
        $this->assign('hotuser',$hotuser);

        $this->assign('title','一个让所有老司机都来的');

    	// var_dump($user);
        $this->display();
    }

    public function getlist()
    {
        $allques = M('question t1')->field("t1.*,t2.nickname,t2.face,t3.cname")->join("user t2 on t1.uid=t2.uid")->join("cate t3 on t1.cid=t3.cid")->order('ctime desc')->select();

        $this->ajaxReturn(['error'=>0,'data'=>$allques]);
    }

    public function show()
    {
    	echo "show";
    }

    public function cate()
    {
        $cid = I('get.cid');

        $hotques = D('question')->getHotTen();

        $cate = M('cate')->select();


        $count = M('question')->where(['cid'=>$cid])->count();

        $Page  = new \Think\Page($count,3);

        $show  = $Page->show();// 分页显示输出


        $allques = M('question t1')->field("t1.*,t2.nickname,t2.face,t3.cname")->join("user t2 on t1.uid=t2.uid")->join("cate t3 on t1.cid=t3.cid")->order('ctime desc')->where(['t1.cid'=>$cid])->limit($Page->firstRow.','.$Page->listRows)->select();


        $this->assign('cate',$cate);

        $this->assign('hotques',$hotques);

        $this->assign('allques',$allques);

        $this->assign('show',$show);

        // var_dump($user);
        $this->display('index');
    }
}